package com.tanhua.server.controller;

import com.tanhua.domain.vo.*;
import com.tanhua.server.service.MomentService;
import com.tanhua.server.service.TodayBestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 圈子功能控制层
 */
@RestController
@RequestMapping("/movements")
public class MomentController {


    @Autowired
    private MomentService momentService;

    /**
     * 发布动态
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity savePublish(PublishVo publishVo,MultipartFile[] imageContent) {
        momentService.savePublish(imageContent,publishVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 好友动态
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity queryPublishByPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<MomentVo> pageResult = momentService.queryPublishByPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 推荐动态（陌生人动态）
     */
    @RequestMapping(value = "/recommend",method = RequestMethod.GET)
    public ResponseEntity queryPublishByRecommendQuanzi(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<MomentVo> pageResult = momentService.queryPublishByRecommendQuanzi(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 用户动态
     * 1.首页推荐用户列表-点击用户进入会查询用户动态
     * 2.我的模块-我的动态-查看当前用户动态
     */
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public ResponseEntity queryPublishByAlbum(@RequestParam(defaultValue = "1") int page,
                                                        @RequestParam(defaultValue = "10") int pagesize,Long userId) {
        PageResult<MomentVo> pageResult = momentService.queryPublishByAlbum(page,pagesize,userId);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 动态点赞
     * publishId:动态id
     */
    @RequestMapping(value = "/{id}/like",method = RequestMethod.GET)
    public ResponseEntity saveComment(@PathVariable("id") String publishId ) {
        int likeCount = momentService.saveComment(publishId);
        return ResponseEntity.ok(likeCount);
    }


    /**
     * 动态取消点赞
     * publishId:动态id
     */
    @RequestMapping(value = "/{id}/dislike",method = RequestMethod.GET)
    public ResponseEntity removeComment(@PathVariable("id") String publishId ) {
        int likeCount = momentService.removeComment(publishId);
        return ResponseEntity.ok(likeCount);
    }


    /**
     * 动态喜欢
     * publishId:动态id
     */
    @RequestMapping(value = "/{id}/love",method = RequestMethod.GET)
    public ResponseEntity saveCommentLove(@PathVariable("id") String publishId ) {
        int loveCount = momentService.saveCommentLove(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * 动态取消喜欢
     * publishId:动态id
     */
    @RequestMapping(value = "/{id}/unlove",method = RequestMethod.GET)
    public ResponseEntity saveCommentUnLove(@PathVariable("id") String publishId ) {
        int unLoveCount = momentService.saveCommentUnLove(publishId);
        return ResponseEntity.ok(unLoveCount);
    }


    /**
     * 单条动态查询
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public ResponseEntity querySinglePublish(@PathVariable("id") String publishId) {
        MomentVo momentVo = momentService.querySinglePublish(publishId);
        return ResponseEntity.ok(momentVo);
    }


    /**
     * 谁看过我(查询5条)
     * http://localhost:10880/movements/visitors
     */
    @RequestMapping(value = "/visitors",method = RequestMethod.GET)
    public ResponseEntity queryVisitors() {
        List<VisitorVo> visitorVoList = momentService.queryVisitors();
        return ResponseEntity.ok(visitorVoList);
    }
}
